package cn.edu.xust.util;

import io.github.biezhi.ome.OhMyEmail;
import io.github.biezhi.ome.SendMailException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static io.github.biezhi.ome.OhMyEmail.SMTP_163;
import static io.github.biezhi.ome.OhMyEmail.SMTP_QQ;

/**
 * @author ufo
 * @version 1.0
 * @date 2023/4/12 16:11
 */


@Slf4j
@Service
public class EmailSendUtil {

    @Resource
    RedisUtil redisUtil;

    public void sendMailForPmsError(String body, String form) throws SendMailException {

        //55分钟之类不要收到相同的警告
        Object ele = redisUtil.get("ele");

        if (ele == null) {
            OhMyEmail.config(SMTP_163(false), "xzemail2024@163.com", "VDUTYLJLXOTZINSA");
            OhMyEmail.subject("水电表失败")
                    .from(form)
                    .to("2575829997@qq.com")
                    .text(body)
                    .send();


            redisUtil.set("ele", 1, 55 * 60);
        }
    }

    public void sendMail(String body, String form) throws SendMailException {
        OhMyEmail.config(SMTP_163(false), "xzemail2024@163.com", "VDUTYLJLXOTZINSA");
        OhMyEmail.subject(form)
                .from(form)
                .to("2575829997@qq.com")
                .text(body)
                .send();

        OhMyEmail.subject(form)
                .from(form)
                .to("chenjian2@jinjianghotels.com.cn")
                .text(body)
                .send();
    }
}
